// mobile bind
// ============

define(['zepto', 'sui', 'zData', 'jrange'], function($){
  return {
    init: function(data) {
      if(location.href.indexOf("#reloaded")==-1){
        location.href=location.href+"#reloaded";
        location.reload();
      }
      
      this.initWithdraw();
      this.initSubmit();
      this.initInputWatch();

    },
    initWithdraw: function() {
      $(document).on("click", ".all-button", function() {
    	// var maxPrice = $(this).data("max").toFixed(2)
        $(".withdraw").val($(this).data("max"))
      })
    },
    initInputWatch: function () {
        $(document).on("input propertychange", ".withdraw", function (e) {
            e.target.value = Math.ceil(e.target.value)
        })
    },
    initSubmit: function() {
      $(document).on("click", ".withdraw-button", function() {
    	var price = $(".withdraw").val()
    	if(price < 100) {
    	    $.toast("满100方可提现！");
    	} else {
	    	$.ajax({
	          url: window.__CTX__.root + '/profile/withdraw',
            type: 'POST',
            dataType: 'json',
            data: {
              amount: price
            },
	          success: function(res) {
	            if (res.code === '0') {
                $.toast(res.message || "操作成功！");
              }else{
                $.toast(res.message || "操作失败！");
              }
	          },
	          fail: function(res) {
	            debugger
              $.toast(res.message || "操作失败！");
            }
	        });
    	}
      })
    }
  }
})